self.addEventListener('install', function (event) {
  event.waitUntil(self.skipWaiting()); // 跳过等待，直接进入active
})

self.addEventListener('active', function (event) {
  event.waitUntil(
    Promise.all([
      self.clients.claim(),
      caches.keys().then(function (cacheList) {
        return Promise.all(
          cacheList.map(function (cacheName) {
            if (cacheName !== 'test-cache-v1') {
              return caches.delete(cacheName)
            }
          })
        )
      })
    ])
  )
})